package com.itheima.huikebackend.controller;

import com.itheima.huikebackend.common.PageResult;
import com.itheima.huikebackend.common.R;
import com.itheima.huikebackend.common.Result;
import com.itheima.huikebackend.dto.CoursePageQueryDTO;
import com.itheima.huikebackend.entity.Course;
import com.itheima.huikebackend.service.CourseService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Du leilei
 * @version 1.0
 * @Description 课程管理
 * @createTime 2023年08月08日 17:32:00
 */
@RestController
@RequestMapping("/clues/course")
public class CourseController {

    @Autowired
    private CourseService courseService;


    /**
     * 课程管理分页
     * @param coursePageQueryDTO
     * @return
     */
    @GetMapping("/list")
    public R<?> page(CoursePageQueryDTO coursePageQueryDTO){

      HashMap<String , Object> map = courseService.page(coursePageQueryDTO);
     return R.success(map);

    }


    /**
     * 添加课程
     * @param course
     * @return
     */
    @PostMapping
    public R addCourse(@RequestBody Course course){
        courseService.addCourse(course);
        return R.success();
    }

    /**
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R delete(@PathVariable Long[] ids){
        courseService.deleteById(ids);
        return R.success();
    }

    /**
     * 查看课程详情
     *
     * @param id id
     * @return {@link Result}<{@link Course}>
     */
    @GetMapping("/{id}")
    public Result<Course> selectCourse(@PathVariable Long id){
           Course course = courseService.selectCourse(id);
           return Result.success(course);
    }

    /**
     * 更新课程
     *
     * @param course 课程
     * @return {@link Result}
     */
    @PutMapping
    public Result updateCourse(@RequestBody Course course){
        courseService.updateCourse(course);
        return Result.success();

    }


    @GetMapping("listselect")
    public Result<Course> listselect(String subject){

        Course course = courseService.listselect(subject);
        return Result.success(course );
    }
}
